package com.haiyangwang1.lesson8;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ExceptionDemo {
    public static void a(){
        a();
    }
    public static void b(){
        long[] array = new long[1024*1024*1024];
    }
    //数组越界异常
    public static void arrayDemo(){
        int[] a = new int[]{1,2,3};
        try{
        for (int i = 0;i <= a.length;i++){//数组下标越界
            System.out.println(a[i]);
        }
        }catch (Exception e){
            System.out.println(e.getCause());
            System.out.println(e.getMessage());

        }
    }

    public void testCheck(){
        FileInputStream fis=null;
        String strDir="";
        strDir=this.getClass().getResource("").getPath();
        try {
            fis=new FileInputStream(strDir+"1.txt");
            fis.close();
        }catch (FileNotFoundException e1){
            System.out.println("e1");
        }catch (IOException e2){
            System.out.println("e2");
        }catch (Exception e3){
            System.out.println("e3");
        }finally {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("textCheck");
    }
    public static void main(String[] args) {
        //main(args);//StackOverflowError  错误    爆栈
        //Exception e=new Exception();
        //a();
        //b();
        arrayDemo();
//        ExceptionDemo e=new ExceptionDemo();
//        e.testCheck();
    }
}
